/**
 * This class contains unit tests for validating the behavior of 
 * ScheduleRoundRobinLeadQueue classes.
 */
@isTest
private class TestScheduleRoundRobinLeadQueue {

    static testMethod void myUnitTest() {
        Test.startTest();
        
        Group g1;
        User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        User u = [select id from user where isActive = true limit 1];
       
        System.runAs (thisUser) {
            Group g;
            g = new Group();
            g.Type = 'Queue';
            g.Name = 'West - Default(ACC)';
            g.DeveloperName = 'ACCQueue';
            
            insert g; 
            
            g1 = [Select id from group where DeveloperName = 'ACCQueue'];
            QueueSObject q = new QueueSObject(SObjectType='Lead', QueueId=g1.Id);
            insert q;
            //if u use the ones in the salesforce u dont have to create members and all
            GroupMember gmem = new GroupMember();
            gmem.GroupId = g1.id;
            gmem.UserOrGroupId = u.Id;
            insert gmem;
        } 
        
        System.runAs (u){
            Lead l=new Lead();
            l.email='john@john.com';
            l.firstname='John';
            l.HasOptedOutOfEmail=false;
            l.lastname='Coppedge';
            l.RecordTypeId=Schema.sObjectType.Lead.getRecordTypeInfosByName().get('West - Prospective Student').getRecordTypeId();
            l.Personal_Email__c='john@john.com';
            l.status='Contacted';
            l.phone='(801) 555-5556';
            DateTime birthDate= DateTime.now(); //DateTime variable
            String birthDate_Formatted_Date = birthDate.format('yyyy-MM-dd');
            l.Birth_Date__c=date.valueof(birthDate_Formatted_Date);
            l.Work_Phone__c='(801) 555-5556';
            l.Country = 'Mexico';
            //l.OwnerId = '005E0000000doY8';        
            insert l;
            
            
            All_Lead_Distribution__c ald = new All_Lead_Distribution__c();
            ald.Lead_Queue_ID__c = g1.id;
            ald.Active__c = true;
            ald.Name = 'AccQ';
            insert ald;
            
            GroupMember gm =[Select UserOrGroupId,groupId from GroupMember where groupId = :g1.Id limit 1];
            /*gm.UserOrGroupId = '005c0000000QOLW';
            gm.GroupId = g1.id;
            insert gm;
            */
            
            l.OwnerId = g1.Id;
            update l;
            
            Lead_Owner_Assignment__c loa = new Lead_Owner_Assignment__c();
            loa.User_Queue_Id__c = g1.id;//'00Gc0000000QplHEAS';//
            loa.Most_Recent_Lead_Assigned_Date__c = system.now();
            loa.Lead_Owner__c = gm.UserOrGroupId;
            insert loa;
            
        }
        
        
        
        BatchRoundRobinLQ batch = new BatchRoundRobinLQ();
       Database.executeBatch(batch,200);
       
        //clsSche_BatchRoundRobinLQ.start(); 
        system.schedule('Round Robin Lead Assignment', clsSche_BatchRoundRobinLQ.CRON_EXP , new clsSche_BatchRoundRobinLQ());
        Test.stopTest();
    }
}